package demo04_8LockProblem;

import java.util.concurrent.TimeUnit;

/**
 * @author kunkun
 * @className Test01
 * @Description0 场景：代码调用发短信线程，中间休息1s，在调用打电话线程，两个线程都用synchronized修饰
 * @Description1 6. 两个对象，发短信中间休息4s，发短信和打电话使用static和synchronized修饰，线程执行顺序？（发短信，打电话）
 * @date 2025/3/5 19:36
 */
public class Test06 {

    public static void main(String[] args) throws InterruptedException {
        Phone phone1 = new Phone();
        Phone phone2 = new Phone();

        new Thread(() -> {phone1.sendMsg();}).start();

        TimeUnit.SECONDS.sleep(1);

        new Thread(() -> {phone2.call();}).start();
    }

    static class Phone {
        public static synchronized void sendMsg(){
            try {
                TimeUnit.SECONDS.sleep(4);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            System.out.println("发短信");
        }
        public static synchronized void call() {
            System.out.println("打电话");
        }
    }
}
